<template>
	<view class="container">
		<uni-card v-for="item in executive" :key="item.id" :thumbnail="`${BASE_URL}/${item.photo}`" class="card" :title="`${item.name}`">
			<view class="cause">职务：{{ item.position }}</view>
			<view class="date">学历：{{ item.education }}</view>
		</uni-card>
		<uni-load-more v-if="isButtom" :status="status" :content-text="contentText" />
		<view class="safe-area-insert-bottom"></view>
	</view>
</template>

<script setup>
import { onMounted, ref, reactive } from 'vue';
import { getExecutiveByEnterpriseId } from '../../api/enterprise.js';
import { onLoad } from '@dcloudio/uni-app';
import { onReachBottom } from '@dcloudio/uni-app';
import { BASE_URL } from '../../utils/system.js';
const enterpriseId = ref(0);

onLoad((options) => {
	enterpriseId.value = options.id;
});

const status = ref('loading');
const isBuutom = ref(false);
const contentText = {
	contentdown: '查看更多',
	contentrefresh: '加载中',
	contentnomore: '没有更多'
};
const queryParams = reactive({
	pageNum: 1,
	pageSize: 10
});
const searchNum = ref(0);
onReachBottom(() => {
	isBuutom.value = true;
	if (status.value === 'loading' || status.value === 'nomore') return;
	queryParams.pageNum++;
	getEnterpriseMSg();
});

const executive = ref([]);

const getEnterpriseMSg = async () => {
	status.value = 'loading';
	try {
		const res = await getExecutiveByEnterpriseId({ enterpriseId: enterpriseId.value, pageNo: queryParams.pageNum, pageSize: queryParams.pageSize });
		if (res.data.executive.length === 0) {
			uni.showToast({
				title: '该公司暂没有更多高管信息',
				icon: 'none'
			});
		}
		if (res.data.executive.length === 0) {
			status.value = 'nomore';
		} else {
			searchNum.value = res.data.totalCount;
			executive.value = [...executive.value, ...res.data.executive];
			status.value = 'more';
		}
	} catch (error) {
		status.value = 'nomore';
	}
};
onLoad(() => {
	getEnterpriseMSg();
});
</script>

<style lang="scss" scoped>
.container {
	.card {
		position: relative;

		.date {
			margin-top: 30rpx;
		}
	}
}
</style>
